<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
	    height: 600px;
	   
	}
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}

	.pagination a{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}
	.pagination span{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;background-color: #fafafa;border: 1px solid #dddddd;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}
	table tr{margin: 6px 0;float: left;width: 100%;}
	.quyu{float: left; margin-right: 5px;}
</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">城市合伙人管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">

		<!-- 操作提示  start -->
		<!-- 操作提示  end -->

		<div class="row padder-v">
			<div class="col-sm-9" style="width:65%;">
				<a href="{:U('Users/city_partner')}" class="btn btn-sm btn-danger" onclick="add_user();"> 返回 </a>
			</div>
		</div>
		<div style="height:0;overflow:hidden;" data="清除浏览器自动填充 勿删">
			<input type="text"   value="" name="111" id="2121">
			<input type="password"  value=" "  name="222" id="211212121">
		</div>
			<div class="table-responsive" style="margin-left: 10px">
				<table class="modal-tab">
					<tbody>
					<php>if($_GET['id']==null){</php>
					<tr>
						<td style="width:80px;">注册手机号</td>
						<td colspan="3">
							<input type="text" class="form-control" id="res_phone" value="" style="float: left;width: 70%;margin-right: 2%;">
							<input type="button" id="search_res_phone" value="搜索" class="btn btn-sm" style="float: left;">
						</td>
					</tr>
					<php>}</php>
					<tr>
						<td style="width:80px;">用户ID</td>
						<td colspan="3">
							<input type="text" id="b_uid"  autocomplete="off" value="{$rs_p.u_id}" readonly>
						</td>
					</tr>


					<tr>
						<td style="width:80px;">级别</td>
						<td colspan="3">
							<select class="form-control m-b" name="level" id="level" onchange="getlevel()">
								<option value="1">省</option>
								<option value="2">市</option>
								<option value="3">区</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="width:80px;">区域</td>
						<td colspan="3">

							<div class="quyu level1">
								<select class="form-control m-b" name="province" id="seleAreaNext" onchange="getProvince(this,'#seleAreaThird')">
									<option value="">请选择省</option>
								</select>
							</div>
							<div class="quyu level2">
								<select class="form-control m-b" name="city" id="seleAreaThird" onchange="getSelCity(this, '#seleAreaFouth')">
									<option value="">请选择市</option>
								</select>
							</div>
							<div class="quyu level3">
								<select class="form-control m-b" name="district" id="seleAreaFouth">
									<option value="-1">请选择区</option>
								</select>
							</div>
						</td>
						<php>
							$b_id=explode(',',$rs_p['b_id']);
						</php>
						<input type="hidden" id="provinceid" value="{$b_id.0}">
						<input type="hidden" id="cityid" value="{$b_id.1}">
						<input type="hidden" id="districtid" value="{$b_id.2}">
						<input type="hidden" id="level_s" value="{$rs_p.level}">
						<input type="hidden" id="u_id" value="{$rs_p.id}">
					</tr>
					<tr>
						<td style="width:80px;">账户状态</td>
						<td colspan="3">


							<label><input type="radio" name="status" value="1" <eq name="rs_p['status']" value="1">checked="checked"</eq>>正常&nbsp;&nbsp;</label>
							<label><input type="radio" name="status" value="0" <eq name="rs_p['status']" value="0">checked="checked"</eq>>锁定</label>
						</td>
					</tr>
					<tr>
						<td style="width:80px;">干涉交易</td>
						<td colspan="3">


							<label><input type="radio" name="order_edit" value="0" <eq name="rs_p['order_edit']" value="0">checked="checked"</eq>>不能&nbsp;&nbsp;</label>
							<label><input type="radio" name="order_edit" value="1" <eq name="rs_p['order_edit']" value="1">checked="checked"</eq>>可以</label>
						</td>
					</tr>

					</tbody>
				</table>
			</div>
		<div class="col-md-offset-3 col-md-9">
			<button class="btn btn-primary btn-sm bq"  value="保存" type="button">保存</button>
			&nbsp; &nbsp; &nbsp;
			<button class="btn btn-primary btn-sm btn-danger" value="取消" type="button" onclick="history.back(-1);">取消</button>
		</div>
</section>
</div>

<include file="Public:footer" />
<script type="text/javascript">
    $(function(){
        if($("#level_s").val()) {
            level_s =$("#level_s").val();
            $('#level').val(level_s)
        }
        if($("#provinceid").val()) {
            provice_id = 0;
        } else {
            provice_id = $("#provinceid").val();
        }
        if($("#provinceid").val() == null) {
            provice_id = 0;
        } else {
            provice_id = $("#provinceid").val();
        }
        if($("#cityid").val() == null) {
            city_id = -1;
        } else {
            city_id = $("#cityid").val();
        }
        if($("#districtid").val() == null) {
            district_id = -1;
        } else {
            district_id = $("#districtid").val();
        }

        if(provice_id == 0) {
            initProvince('#seleAreaNext');
        } else {
            load('province', provice_id, 'city', city_id, 'district', district_id);
        }
        getlevel();
        $('#search_res_phone').click(function(){
            var phone=$('#res_phone').val();
            if(phone){
                $.get('/store/search_phone2/phone/'+phone, function(data) {
                    if(data==0){
                        layer.msg('该用户不存在！');

                    }else if(data==1){
                        layer.msg('该用户已成为城市合伙人！');
                    }else{
                        $('#b_uid').val(data.id);
                    }
                });
            }else{
                layer.msg('请输入绑定手机号');
            }
        })

    })
	$('.bq').click(function () {
		var b_uid=$('#b_uid').val();
		var level= $('#level').val();
        var id= $('#u_id').val();
        if(b_uid==''){
            layer.msg('请先选择绑定用户');
            return;
		}

        if(level==1){
            if($('#seleAreaNext').val()){
                var b_id=$('#seleAreaNext').val();
			}else{
                layer.msg('请选择省');
                return;
			}

		}

        if(level==2){
            if($('#seleAreaNext').val()&&$('#seleAreaThird').val()>0){
           		 var b_id=$('#seleAreaNext').val()+','+$('#seleAreaThird').val();
            }else{
                layer.msg('请选择省市');
                return;
            }

        }
        if(level==3){
            if($('#seleAreaNext').val()&&$('#seleAreaThird').val()>0&&$('#seleAreaFouth').val()>0){
            var b_id=$('#seleAreaNext').val()+','+$('#seleAreaThird').val()+','+$('#seleAreaFouth').val();
            }else{
                layer.msg('请选择省市区');
                return;
            }
        }
        var status=$("input[name='status']:checked").val();
        var order_edit=$("input[name='order_edit']:checked").val();
        $.post(
            "{:U('Users/city_partner_edit')}",
			{id:id,u_id:b_uid,level:level,b_id:b_id,status:status,order_edit:order_edit},
			function(result){
                if(result==0){
                    layer.msg('添加失败');
				 }
				if(result==1){
                    layer.msg('添加成功');
                    setTimeout(window.location.href='/Users/city_partner.html',1000)
                }
                if(result==2){
                    layer.msg('编辑成功');
                    setTimeout(window.location.href='/Users/city_partner.html',1000)
                }
                if(result==3){
                    layer.msg('编辑失败');
                }
                if(result==4){
                    layer.msg('该账户已存在！');
                }

      		}
        );
    })
	function  getlevel() {
        level= $('#level').val();
		if(level==1){
			$('.level1').show();
			$('.level2').hide();
			$('.level3').hide();
		}
        if(level==2){
            $('.level1').show();
            $('.level2').show();
            $('.level3').hide();
        }
        if(level==3){
            $('.level1').show();
            $('.level2').show();
            $('.level3').show();
        }
    }
</script>

<script src="/NewAdmin/js/init_address.js"></script>